<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Boot WMS</title> 
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css"> 
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> 
  <!-- Tempusdominus Bbootstrap 4 -->
  <link rel="stylesheet" href="plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
  <!-- iCheck -->
  <link rel="stylesheet" href="plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- JQVMap -->
  <link rel="stylesheet" href="plugins/jqvmap/jqvmap.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
  <!-- overlayScrollbars -->
  <link rel="stylesheet" href="plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <!-- Daterange picker -->
  <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker.css">
    
  <!-- jsGrid -->
  <link rel="stylesheet" href="plugins/jsgrid/jsgrid.min.css">
  <link rel="stylesheet" href="plugins/jsgrid/jsgrid-theme.min.css">
  
  <!-- jquery-ui -->
  <link rel="stylesheet" href="plugins/jquery-ui/jquery-ui.min.css">
  
  <!-- summernote -->
  <link rel="stylesheet" href="plugins/summernote/summernote-bs4.css"> 
  <!-- Google Font: Source Sans Pro -->
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
  <style>
  
  .showAdd1 {
  	display: none;
  }
  
  .showAdd2 {
  	display: block;
  }
  </style>
</head>
<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">

  <!-- Navbar -->
  <nav class="main-header navbar navbar-expand navbar-white navbar-light">  
	<div id="test1"></div> 
	<div id="test2"></div>
    
    <ul class="navbar-nav ml-auto"> 
		<div id="test3"></div> 
		<div id="test4"></div>
		<li class="nav-item">
		  <a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#">
		    <i class="fas fa-th-large"></i>
		  </a>
		</li>
    </ul>
  </nav>
  <!-- /.navbar -->

  <aside class="main-sidebar sidebar-dark-primary elevation-4">
  	<div id="logo1"></div> 
    <div class="sidebar">
		<div id="user1"></div>
		<nav class="mt-2">
			 <ul class="nav nav-pills nav-sidebar flex-column" 
			 	 data-widget="treeview" 
			 	 role="menu" 
			 	 data-accordion="false">
			 	<div id="menu1"></div> 
		 	 </ul>
		</nav>
  	</div> 
  </aside>  

  
  <div class="content-wrapper">
  	<!-- 主区域标题 chaXun_xx -->
    <section class="content-header">
      <div class="container-fluid">
      	<div class="row mb-2">
      		<div class="col-sm-9">
      		  <h1 class="m-0 text-dark">
   				入库信息
      		  </h1>
      		</div>
      		<div class="col-sm-1">
      		<button type="button"
	   				class="btn btn-block btn-primary"
	   				data-toggle="modal"
	   				data-target="#modal-addnewASN"      		
	   				onclick = "clearField()" 
      		>
      		  新增ASN
      		</button>
      		</div>
   			<div class="col-sm-2">
   				<ol class="breadcrumb float-sm-right">
   					<li class="breadcrumb-item"><a href="./index.html">主页</a></li>
   					<li class="breadcrumb-item active">ASN信息</li>
   				</ol>
   			</div>
      	</div>
      
      </div>
   
    </section>
    <section class="content">
    	<div class="card">
    		<div class="card-header">
    			<h3 class="card-title">ASN列表</h3>
    		</div>
    		<div class="card-body">
    			<div id="jsGrid1"></div>
    		</div>
    	</div>
    </section>
    
  </div>
  
 <div class="modal fade" id="modal-detailASN">
   <div class="modal-dialog modal-xl"> 
   	<div class="modal-content">
   	  <div class="modal-header">
   	  	<h4 class="modal-title">
   	  		ASN详情
   	  	</h4>
   	  	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
   	  	  <span aria-hidden="true">&times;</span>
   	  	</button>
   	  </div>
      <div class="modal-body">
      	<div class="card">
      		<div class="card-header">
      		ASN: &nbsp; <span id="idNo"></span> &nbsp; 
      		</div>
      		<div class="card-body">
      		<form action="" name="post_form2" id="post_form2" role="form">
	      		<div class="row">
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>入库编号</label>
							<input type="text" id="ASNID" name="ASNID" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>客户编号</label>
							<input type="text" id="storekey" name="storekey" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>创建日期</label>
							<input type="text" id="createDate" name="createDate" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>接收日期</label>
							<input type="text" id="receiveDate" name="receiveDate" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>总件数</label>
							<input type="text" id="totalPkg" name="totalPkg" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>件数类型</label>
							<input type="text" id="pkgType" name="pkgType" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      		</div>
	      		<div class="row">
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>业务编码</label>
							<input type="text" id="bussNum" name="bussNum" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>发票编码</label>
							<input type="text" id="InvoiceNum" name="InvoiceNum" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>备注1</label>
							<input type="text" id="remark1" name="remark1" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>备注2</label>
							<input type="text" id="remark2" name="remark2" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>备注3</label>
							<input type="text" id="remark3" name="remark3" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>备注4</label>
							<input type="text" id="remark4" name="remark4" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      		</div>
	      		<div class="row">
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>备注5</label>
							<input type="text" id="remark5" name="remark5" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>备注6</label>
							<input type="text" id="remark6" name="remark6" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>状态</label>
							<input type="text" id="status" name="status" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					<div class="form-group">
		  					<label>入库单号</label>
							<input type="text" id="ASNNum" name="ASNNum" 
								class="form-control" placeholder="">
	  					</div>
					</div>
	      			<div class="col-sm-2">
	  					
					</div>
	      			<div class="col-sm-2">
	  					
					</div>
	      		</div>
	      	</form>
      		</div>
      	</div>
      	<div id="addItem1" class="card showAdd1">
      		<div class="card-header"> 
	      		<div class="row">
	      			<div class="col-sm-2">
      					添加详情 
					</div>
	      			<div class="col-sm-2">
	  					
					</div>
	      			<div class="col-sm-2">
	  					
					</div>
	      			<div class="col-sm-2">
	  					
					</div>
	      			<div class="col-sm-2">
	  					<button type="button" class="btn btn-block btn-default btn-xs" onclick="closeDetail()">
		      			仅关闭
		      	  	  </button> 
					</div>
	      			<div class="col-sm-2">
		      		  <button type="button" class="btn btn-block btn-default btn-xs" onclick="saveDetail()">
		      			详情保存关闭
		      	  	  </button> 
					</div>
	      		</div>
      		</div>
      		<div class="card-body">
      	    <form action="" name="post_form1" id="post_form1" role="form">
      			<div class="row">
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>物料名称</label>
							<input type="text" id="sku" name="sku" 
								class="form-control" placeholder="">
							<input type="hidden" id="ASNNum" name="ASNNum" value="">
	  					</div>
      				</div>
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>物料中文名</label>
							<input type="text" id="skuCN" name="skuCN" 
								class="form-control" placeholder=""> 
							<input type="hidden" id="id" name="id" value="">
	  					</div>
      				</div>
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>物料英文名</label>
							<input type="text" id="skuEN" name="skuEN" 
								class="form-control" placeholder="">
	  					</div>
      				</div>
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>法定单位</label>
							<input type="text" id="legalUnit" name="legalUnit" 
								class="form-control" placeholder="">
	  					</div>
      				</div>
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>最小包装数量</label>
							<input type="text" id="moqNum" name="moqNum" 
								class="form-control" placeholder="">
	  					</div>
      				</div>
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>库位ID</label>
							<input type="text" id="locID" name="locID" 
								class="form-control" placeholder="">
	  					</div>
      				</div>
      			</div>
      			<div class="row">
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>备注1</label>
							<input type="text" id="remark1" name="remark1" 
								class="form-control" placeholder="">
	  					</div>
      				</div>
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>备注2</label>
							<input type="text" id="remark2" name="remark2" 
								class="form-control" placeholder="">
	  					</div>
      				</div>
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>备注3</label>
							<input type="text" id="remark3" name="remark3" 
								class="form-control" placeholder="">
	  					</div>
      				</div>
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>备注4</label>
							<input type="text" id="remark4" name="remark4" 
								class="form-control" placeholder="">
	  					</div>
      				</div>
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>备注5</label>
							<input type="text" id="remark5" name="remark5" 
								class="form-control" placeholder="">
	  					</div>
      				</div>
      				<div class="col-sm-2">
      					<div class="form-group">
		  					<label>备注6</label>
							<input type="text" id="remark6" name="remark6" 
								class="form-control" placeholder="">
	  					</div>
      				</div>
      			</div>
      		</form>
      		</div>      		
      	</div>
      	<div class="card">
      		<div class="card-header"> 
      		<div class="row" id="showDetail1">
      		  <div class="col-sm-2">
	  			ASN详情		
			  </div>
      		  <div class="col-sm-2">
      		    
      		  </div> 
      		  <div class="col-sm-2">
      		    <button type="button" id="dsava1" class="btn btn-block btn-default btn-xs" onclick="saveASN()">
      			  保存关闭
      	  	    </button>
      		  </div> 
      		  <div class="col-sm-2">
      		    <button type="button" id="dsava2" class="btn btn-block btn-default btn-xs" onclick="finishRecvCargo()">
      			  结束收货
      	  	    </button>  
      		  </div> 
      		  <div class="col-sm-2">
      		    <button type="button" id="dsava3" class="btn btn-block btn-default btn-xs" onclick="receiveASN()">
      			  收货上架
      	  	    </button> 
      		  </div> 
      		  <div class="col-sm-2">
      		    <button type="button" id="dsava4" class="btn btn-block btn-default btn-xs" onclick="addItemDetail()">
      			  新增详情
      	  	    </button> 
      		  </div> 
      		</div>
      		</div>
      		<div class="card-body">
      			<div id="jsGrid2"></div>
      		</div>
      	</div>
      </div>
   	</div>
   </div>
 </div>
  

<div class="modal fade" id="modal-addnewASN">
 <div class="modal-dialog modal-lg">
  	<div class="modal-content">
  	  <div class="modal-header">
  	  	<h4 class="modal-title">新增ASN</h4>
  	  	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
  	  	  <span aria-hidden="true">&times;</span>
  	  	</button>
  	  </div>
  	  
     <div class="modal-body"> 
       <p>新增窗口</p>
    <hr/> 
 		<div class="card-body">
      	  <form action="" name="post_form" id="post_form" role="form">
      	  	<div class="row">
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>入库编号</label>
			  <input type="text" id="ASNID" name="ASNID" 
			  class="form-control" placeholder="">
			</div>
		  </div>
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>客户编号</label>
			  <!-- <input type="text" id="storekey" name="storekey" 
			  class="form-control" placeholder=""> -->

			  <select class="form-control" id="storekey" name="storekey">
			  	<option value="default" selected="selected">默认客户</option>
			  </select>


			</div>
		  </div>
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>总件数</label>
			  <input type="text" id="totalPkg" name="totalPkg" 
			  class="form-control" placeholder="">
			</div>
		  </div>
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>件数类型</label>
			  <!-- <input type="text" id="pkgType" name="pkgType" 
			  class="form-control" placeholder=""> -->
			  <select id="pkgType" name="pkgType" class="form-control">
			    <option value="mixed" selected="selected">混合</option>
			    <option value="package">件</option>
			    <option value="box">箱</option>
			    <option value="bag">包</option>
				</select>
			</div>
		  </div>
		</div>
      	  	<div class="row">
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>业务编码</label>
			  <input type="text" id="bussNum" name="bussNum" 
			  class="form-control" placeholder="">
			</div>
		  </div>
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>发票编码</label>
			  <input type="text" id="InvoiceNum" name="InvoiceNum" 
			  class="form-control" placeholder="">
			</div>
		  </div>
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>备注1</label>
			  <input type="text" id="remark1" name="remark1" 
			  class="form-control" placeholder="">
			</div>
		  </div>
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>备注2</label>
			  <input type="text" id="remark2" name="remark2" 
			  class="form-control" placeholder="">
			</div>
		  </div>
		</div>
      	  	<div class="row">
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>备注3</label>
			  <input type="text" id="remark3" name="remark3" 
			  class="form-control" placeholder="">
			</div>
		  </div>
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>备注4</label>
			  <input type="text" id="remark4" name="remark4" 
			  class="form-control" placeholder="">
			</div>
		  </div>
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>备注5</label>
			  <input type="text" id="remark5" name="remark5" 
			  class="form-control" placeholder="">
			</div>
		  </div>
		  <div class="col-sm-3">
			<div class="form-group">
			  <label>备注6</label>
			  <input type="text" id="remark6" name="remark6" 
			  class="form-control" placeholder="">
			</div>
		  </div>
		</div>
      	  </form>
 		</div>
     </div>
  	  <div class="modal-footer justify-content-between">
       <button type="button" class="btn btn-default" data-dismiss="modal">
       	关闭</button>
       <button type="button" onclick="confirmedAdd()" data-dismiss="modal" 
       	class="btn btn-primary">确认添加</button>
     </div>
  	</div>
 </div>
</div>
 
 
<div class="modal fade" id="modal-deleteASN">
   <div class="modal-dialog modal-lg">
   	<div class="modal-content">
   	  <div class="modal-header">
   	  	<h4 class="modal-title">
   	  		删除ASN
   	  	</h4>
   	  	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
   	  	  <span aria-hidden="true">&times;</span>
   	  	</button>
   	  </div>
   	  
      <div class="modal-body"> 
      	<p>
      		是否要删除编号为： &nbsp; <span id="idNo"></span> &nbsp; 的ASN。
      	</p>
      </div>
      <div class="modal-footer justify-content-between">
        <button type="button" class="btn btn-default" data-dismiss="modal">
        	关闭</button>
        <button type="button" onclick="confirmedDel()" data-dismiss="modal" 
        	class="btn btn-primary">确认删除</button>
      </div>
   	</div>
   </div>
 </div> 
  
   
<div class="modal fade" id="modal-deleteASNDetail">
   <div class="modal-dialog modal-lg">
   	<div class="modal-content">
   	  <div class="modal-header">
   	  	<h4 class="modal-title">
   	  		删除ASN 详情
   	  	</h4>
   	  	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
   	  	  <span aria-hidden="true">&times;</span>
   	  	</button>
   	  </div>
   	  
      <div class="modal-body"> 
      	<p>
      		是否要删除编号为： &nbsp; <span id="idNo"></span> &nbsp; 的ASN 详情。
      	</p>
      </div>
      <div class="modal-footer justify-content-between">
        <button type="button" class="btn btn-default" data-dismiss="modal">
        	关闭</button>
        <button type="button" onclick="confirmedDetailDel()" data-dismiss="modal" 
        	class="btn btn-primary">确认删除</button>
      </div>
   	</div>
   </div>
</div> 
  
  
<div id="footer"></div>
  
<!-- jQuery -->
<script src="plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>

<!-- jsgrid -->
<script src="plugins/jsgrid/jsgrid.min.js"></script>

<!-- AdminLTE App -->
<script src="dist/js/adminlte.js"></script>
</body>
<script type="text/javascript">

var gid = 0;
var gdid = 0;
var dupd = false;
var ddata = {};
var detailList = [];

function timestampToString(timestamp) {
	
	if(timestamp == null || timestamp=='' || timestamp == undefined){
		return '';
	}
	
    // 创建一个新的 Date 对象，使用传入的时间戳（注意：JavaScript 的 Date 对象期望的是毫秒）
    const date = new Date(timestamp);

    // 获取各个部分
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0'); // getMonth() 返回值是 0-11
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');

    // 格式化输出
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}  
	
	(function($){

    'use strict';
		
		console.log("start");

		localStorage.setItem("menuId", 2);
		
		//$("#mainHeader").load("mainHeader1.html");
		$("#test1").load("test1.html");
		$("#test2").load("test2.html");
		$("#test3").load("test3.html");
		$("#test4").load("test4.html");
		$("#logo1").load("logo1.html");
		$("#user1").load("user1.html");
		$("#menu1").load("menu1.html");
		$("#footer").load("foot.html");

		initialData();
		iniTableData(); 


		setTimeout(()=> { 
			listStoreKeySelect();
		},555)
        
	})(jQuery);
	
	function checkDetail(){
		console.log("checkDetail()");
		
		console.log("detailList-=>",JSON.stringify(detailList))
		var tmp1 = $('#jsGrid2');
		console.log("tmp1-=>",tmp1);
		var tmp2 = $('#jsGrid2').jsGrid();
		console.log("tmp2-=>",tmp2);
		return true;
	}
	
	function receiveASN(){
		console.log("receiveASN()");
		
		if(checkDetail()){
			return;
		}
	}
    
	function listStoreKeySelect(){
		console.log("listStoreKeySelect 初始化储存户列表");

		var url2 = '../api/baseInfo/cmn/listStoreKey';//listStoreKey
		var data1 = {};
		var optionsHtml = '';

		$.ajax({
			type: "post",
			url: url2,
			dataType: "json",
			data: data1,
			success: function(res) {
				console.log("listStoreKeySelect ajax-=>",res);

				$.each(res, function(index, value) {
				    optionsHtml += '<option value="' + value.storeKey + '">' + value.storeName + '</option>';
				}); 
				console.log("optionsHtml-=>",optionsHtml);
				//$("#storekey").html(optionsHtml);
				$("#modal-addnewASN #storekey").append(optionsHtml);

			},
			error: function(){
				alert("后台访问错误，请联系管理员！");

			}
		})
	}

    function finishRecvCargo(){
        console.log("finishRecvCargo()-=》",gid)
        
		console.log('confirmedDel()');
		var data1 = {"id":gid};
		var url1 = '../api/baseInfo/serv_meth/asnService/finishASNReceive';

		$.ajax({
			url: url1,
			type: "POST",
			data: data1,
			success: function(res){
				console.log("完成提交成功");
			}
		});
        $('#modal-detailASN').modal('hide');
		setTimeout(()=> {
			iniTableData(); 
		},555)
        
    }
    
	function clearField(){
		console.log("clearField()");

		$('#modal-addnewASN #ASNID').val('');
		$('#modal-addnewASN #storekey').val('');
		$('#modal-addnewASN #totalPkg').val('');
		$('#modal-addnewASN #pkgType').val('');
		$('#modal-addnewASN #bussNum').val('');
		$('#modal-addnewASN #InvoiceNum').val('');
		$('#modal-addnewASN #remark1').val('');
		$('#modal-addnewASN #remark2').val('');
		$('#modal-addnewASN #remark3').val('');
		$('#modal-addnewASN #remark4').val('');
		$('#modal-addnewASN #remark5').val('');
		$('#modal-addnewASN #remark6').val('');
	}

	function saveASN(){
		console.log("saveASN()")
		//modal-detailASN  post_form2
		var formData = $("#modal-detailASN #post_form2").serialize();
		var url1 = '../api/baseInfo/serv_meth/asnService/update';
		formData = formData + "&id="+gid;
		$.ajax({
			url:url1,
			type: "POST",
			data: formData,
			success: function(res){
				console.log("修改提交成功");
			}
		});
		
		$('#modal-detailASN').modal('hide');

		setTimeout(()=> {
			iniTableData();
		},555)
	}
	
	function confirmedDetailDel(){
		console.log("confirmedDetailDel()");

		var data1 = {"did":gdid};
		var url1 = '../api/baseInfo/serv_meth/asnService/deleteDetail';

		$.ajax({
			url: url1,
			type: "POST",
			data: data1,
			success: function(res){
				console.log("删除详情提交成功");
			}
		});

		setTimeout(()=> {
			iniDetailTableData();
		},555)
		
	}
	
	function closeDetail(){
		console.log("closeDetail()");

		$('#addItem1').addClass('showAdd1');
		$('#addItem1').removeClass('showAdd2');
		
	}
	
	function saveDetail(){
		console.log("saveDetail()")
		
		var formData = $("#modal-detailASN #addItem1 #post_form1").serialize();
		console.log("formData-=>",formData);
		var url1 = '';
		if(dupd){
			url1 = '../api/baseInfo/serv_meth/asnService/updateDetail';
			formData = formData +'&did='+gdid;
			var formData1 = $("#modal-detailASN #addItem1 #post_form1").serializeArray();
			console.log("formData1-=>",formData1);
			const formObject = formData1.reduce((obj,item)=>{
				obj[item.name] = item.value;
				return obj;
			},{});
			console.log("formObject-=>",formObject);
			var data2 = $.extend(ddata,formObject);
			console.log("data2-=>",data2)
			$.ajax({
				url: url1,
				type: "POST",
				data: data2,
				success: function(res){
					console.log("ASN详情新增或更新提交成功")
				}			
			}); 
			dupd = false;
		}else{
			url1 = '../api/baseInfo/serv_meth/asnService/addNewDetail';
		
			$.ajax({
				url: url1,
				type: "POST",
				data: formData,
				success: function(res){
					console.log("ASN详情新增或更新提交成功")
				}			
			}); 
		}

		setTimeout(()=> {
			iniDetailTableData();
		},555)
		
		$('#addItem1').addClass('showAdd1');
		$('#addItem1').removeClass('showAdd2');
		
	}

	function iniDetailTableData(){
		console.log("iniDetailTableData()");
		

		var data1 = {"id":gid};
		var url1 = '../api/baseInfo/serv_meth/asnService/selectDetailById';
		
		$.ajax({
			type: "post",
			url: url1,
			dataType: "json",
			paging: true,
			pageSize: 10,
			data: data1,
			success: function(res2){
				console.log(res2);
				
				detailList = res2;
				
				$('#jsGrid2').jsGrid({
					height: "310px",
					width: "100%",
					paging: true,
					pageSize: 5,
					data: res2,
					rowDoubleClick: function(args){
						showDetailDialog4(args);
					},
					fields:[
						{name:"did", type: "number", width:55,title:"编号"},
						//{name:"id", type: "number", width:55,title:"主键"},
						//{name:"aSNNum", type: "number", width:55,title:"ASN"},
						//{name:"seq", type: "number", width:55,title:"序号"},
						//{name:"itemNo", type: "number", width:55,title:"项号"},
						{name:"sku", type: "number", width:55,title:"名称"},
						{name:"skuCN", type: "number", width:100,title:"中文"},
						{name:"skuEN", type: "number", width:100,title:"英文"},
						{name:"legalUnit", type: "number", width:55,title:"法单"},
						{name:"moqNum", type: "number", width:100,title:"最小包数"},
						{name:"locID", type: "number", width:75,title:"库位"},
						{name:"lotID", type: "number", width:55,title:"批次"},
						{name:"createDate", type: "number", width:155,title:"创建时间",
							editButton: false,
							itemTemplate: function(value,item){
								return timestampToString(value)
							}							
						},
						{name:"status", type: "number", width:75,title:"状态"},
						{name:"remark1", type: "number", width:50,title:"注1"},
						{name:"remark2", type: "number", width:50,title:"注2"},
						{name:"remark3", type: "number", width:50,title:"注3"},
						{name:"remark4", type: "number", width:50,title:"注4"},
						{name:"remark5", type: "number", width:50,title:"注5"},
						{name:"remark6", type: "number", width:50,title:"注6"}, 
						{
							type:"control",
							width: 85,
	                        modeSwitchButton: true,
							itemTemplate: function(value,item) {
								return $("<button>").attr("type","button").text("删除")
									.addClass("btn btn-block btn-default")
									.on("click",function(e){
										showDetailDialog3("del",{},value,item);
									});
							}
						}
					]
				});
			},
			error:function(e){
				console.log(e);	
			}
		})
		
	}
	
	function addItemDetail(){
		console.log("addItemDetail()");
		
		$('#addItem1').addClass('showAdd2');
		$('#addItem1').removeClass('showAdd1');
		

		$('#addItem1 #id').val(gid);

		$('#addItem1 #sku').val('');
		$('#addItem1 #skuCN').val('');
		$('#addItem1 #skuEN').val('');
		$('#addItem1 #legalUnit').val('');
		$('#addItem1 #moqNum').val('');
		$('#addItem1 #locID').val('');
		
		$('#addItem1 #remark1').val('');
		$('#addItem1 #remark2').val('');
		$('#addItem1 #remark3').val('');
		$('#addItem1 #remark4').val('');
		$('#addItem1 #remark5').val('');
		$('#addItem1 #remark6').val('');
		
	}
	
	function confirmedDel(){
		console.log('confirmedDel()');
		var data1 = {"id":gid};
		var url1 = '../api/baseInfo/serv_meth/asnService/delete';

		$.ajax({
			url: url1,
			type: "POST",
			data: data1,
			success: function(res){
				console.log("删除提交成功");
			}
		});

		setTimeout(()=> {
			iniTableData(); 
		},555)
		
	}
	
	function confirmedAdd(){
		console.log("confirmedAdd()");
		
		var formData = $("#modal-addnewASN #post_form").serialize();
		console.log("formData-=>",formData);
		var url1 = '../api/baseInfo/serv_meth/asnService/addNew';

		$.ajax({
			url: url1,
			type: "POST",
			data: formData,
			success: function(res){
				console.log("ASN入库新增提交成功")
			}			
		});		
		
		setTimeout(()=> {
			iniTableData();
		},555)
	}

	function iniTableData(){
		console.log("iniTableData()");
		
		var data1 = {};
		var url1='../api/baseInfo/serv_meth/asnService/showList';
		
		$.ajax({
			type: "post",
			url: url1,
			dataType: "json",
			data: data1,
			success: function(res){
				console.log(res);
				
				$("#jsGrid1").jsGrid({
					height: "510px",
					width: "100%",
					paging: true,
					pageSize: 10,
					data: res,
					rowDoubleClick: function(args){
						showDetailDialog2(args);
					},
					fields:[
						{name:"id", type: "number", width:55,title:"编号"},
						//{name:"aSNID", type: "number", width:55,title:"入库编号"},
						{name:"aSNNum", type: "number", width:155,title:"入库单号"},
						{name:"storekey", type: "number", width:85,title:"客户编号"},
						{name:"createDate", type: "number", width:105,title:"创建日期",
							editButton: false,
							itemTemplate: function(value,item){
								return timestampToString(value)
							}
						},
						{name:"receiveDate", type: "number", width:150,title:"接收如期",
							editButton: false,
							itemTemplate: function(value,item){
								return timestampToString(value)
							}
						},
						{name:"totalPkg", type: "number", width:75,title:"总件数"},
						{name:"pkgType", type: "number", width:100,title:"件数类型"},
						{name:"bussNum", type: "number", width:55,title:"业务编码"},
						{name:"invoiceNum", type: "number", width:55,title:"发票编码"},
						{name:"status", type: "number", width:75,title:"状态"},
						{name:"remark1", type: "number", width:55,title:"备1"}, 
						{name:"remark2", type: "number", width:55,title:"备2"}, 
						{name:"remark3", type: "number", width:55,title:"备3"}, 
						{name:"remark4", type: "number", width:55,title:"备4"}, 
						{name:"remark5", type: "number", width:55,title:"备5"}, 
						{name:"remark6", type: "number", width:55,title:"备6"}, 
						{
							type:"control",
							width: 85,
	                        modeSwitchButton: true,
							itemTemplate: function(value,item) {
                            
                                if(item.status === 'FINISH'){
                                    return '不可删除'
                                }
                                
								return $("<button>").attr("type","button").text("删除")
									.addClass("btn btn-block btn-default")
									.on("click",function(e){
										showDetailDialog1("del",{},value,item);
									});
							}
						}
					]
				})
				
			},
			error: function(e){
				console.log(e);
			}
		})
	}
/*
 {
		type:"control",
		width: 85,
     modeSwitchButton: true,
		itemTemplate: function(value,item) {
			return $("<button>").attr("type","button").text("编辑")
				.addClass("btn btn-block btn-default")
				.on("click",function(e){
					showDetailDialog1("upd",{},value,item);
				});
		}
	},
*/	
	
	function showDetailDialog1(a,b,c,d){
		console.log("showDetailDialog1-=>",a,b,c,d);
		gid = d.id; 
		
		if(a==='del'){
			$('#modal-deleteASN').modal('show');
			$('#modal-deleteASN #idNo').text(d.id);			
		}
		/*setTimeout(()=> {
			iniTableData();
		},555)*/
	}

	function showDetailDialog2(e){
		console.log("showDetailDialog2-=>",e);
		gid = e.item.id; 
		
		var data1 = {"id":e.item.id};
		var url1 = '../api/baseInfo/serv_meth/asnService/selectDetailById';
		
		$.ajax({
			type: "post",
			url: url1,
			dataType: "json",
			paging: true,
			pageSize: 10,
			data: data1,
			success: function(res2){
				console.log(res2);
				$('#jsGrid2').jsGrid({
					height: "310px",
					width: "100%",
					paging: true,
					pageSize: 5,
					data: res2,
					rowDoubleClick: function(args){
						showDetailDialog4(args);
					},
					fields:[
						{name:"did", type: "number", width:55,title:"编号"},
						//{name:"id", type: "number", width:55,title:"主键"},
						//{name:"aSNNum", type: "number", width:55,title:"ASN"},
						//{name:"seq", type: "number", width:55,title:"序号"},
						//{name:"itemNo", type: "number", width:55,title:"项号"},
						{name:"sku", type: "number", width:55,title:"名称"},
						{name:"skuCN", type: "number", width:100,title:"中文"},
						{name:"skuEN", type: "number", width:100,title:"英文"},
						{name:"legalUnit", type: "number", width:55,title:"法单"},
						{name:"moqNum", type: "number", width:100,title:"最小包数"},
						{name:"locID", type: "number", width:75,title:"库位"},
						{name:"lotID", type: "number", width:55,title:"批次"},
						{name:"createDate", type: "number", width:155,title:"创建时间",
							editButton: false,
							itemTemplate: function(value,item){
								return timestampToString(value)
							}							
						},
						{name:"status", type: "number", width:75,title:"状态"},
						{name:"remark1", type: "number", width:50,title:"注1"},
						{name:"remark2", type: "number", width:50,title:"注2"},
						{name:"remark3", type: "number", width:50,title:"注3"},
						{name:"remark4", type: "number", width:50,title:"注4"},
						{name:"remark5", type: "number", width:50,title:"注5"},
						{name:"remark6", type: "number", width:50,title:"注6"}, 
						{
							type:"control",
							width: 85,
	                        modeSwitchButton: true,
							itemTemplate: function(value,item) {
								return $("<button>").attr("type","button").text("删除")
									.addClass("btn btn-block btn-default")
									.on("click",function(e){
										showDetailDialog3("del",{},value,item);
									});
							}
						}
					]
				});
			},
			error:function(e){
				console.log(e);	
			}
		})
		
		
		$('#modal-detailASN').modal('show');
		
		$('#modal-detailASN #idNo').text(e.item.id);
		$('#modal-detailASN #ASNNum').val(e.item.aSNNum);
		$('#modal-detailASN #ASNID').val(e.item.aSNID);
		
		$('#modal-detailASN #storekey').val(e.item.storekey);
		$('#modal-detailASN #createDate').val(timestampToString(e.item.createDate));
		$('#modal-detailASN #receiveDate').val(timestampToString(e.item.receiveDate));
		$('#modal-detailASN #totalPkg').val(e.item.totalPkg);
		$('#modal-detailASN #pkgType').val(e.item.pkgType);
		$('#modal-detailASN #bussNum').val(e.item.bussNum);
		$('#modal-detailASN #InvoiceNum').val(e.item.invoiceNum);
		$('#modal-detailASN #status').val(e.item.status);
		$('#modal-detailASN #remark1').val(e.item.remark1);
		$('#modal-detailASN #remark2').val(e.item.remark2);
		$('#modal-detailASN #remark3').val(e.item.remark3);
		$('#modal-detailASN #remark4').val(e.item.remark4);
		$('#modal-detailASN #remark5').val(e.item.remark5);
		$('#modal-detailASN #remark6').val(e.item.remark6);
		
		//
        if(e.item.status === 'FINISH'){
            //$('#showDetail1').addClass('showAdd1');
            //$('#showDetail1').removeClass('showAdd2');//dsava1
            $('#dsava1').addClass('showAdd1');
            $('#dsava2').addClass('showAdd1');
            $('#dsava3').addClass('showAdd1');
            $('#dsava4').addClass('showAdd1');
        }else{
            //$('#showDetail1').addClass('showAdd2');
            //$('#showDetail1').removeClass('showAdd1');   
            $('#dsava1').removeClass('showAdd1');
            $('#dsava2').removeClass('showAdd1');
            $('#dsava3').removeClass('showAdd1');
            $('#dsava4').removeClass('showAdd1'); 
        }
        
	}
/*
aSNID: 1
aSNNum: "ASN0000000000001"
bussNum: "00001"
createDate: 1520407689319
id: 1
invoiceNum: "A0021"
pkgType: "BOX"
receiveDate: 1520409083981
status: "RECEIVED"
storekey: "apple"
totalPkg: 0
*/	
    function showDetailDialog3(a,b,c,d){
		console.log("showDetailDialog3-=>",a,b,c,d);
		gdid = d.did; 
		
		if(a==='del'){
			$('#modal-deleteASNDetail').modal('show');
			$('#modal-deleteASNDetail #idNo').text(d.did);			
		}
		
	}
	
    function showDetailDialog4(e){
    	console.log("showDetailDialog4-=>",e)
    	gdid = e.item.did; 
    	dupd = true;
			$('#addItem1').addClass('showAdd2');
			$('#addItem1').removeClass('showAdd1');
			
			ddata = e.item;

			$('#addItem1 #id').val(gid);

			$('#addItem1 #sku').val(e.item.sku);
			$('#addItem1 #skuCN').val(e.item.skuCN);
			$('#addItem1 #skuEN').val(e.item.skuEN);
			$('#addItem1 #legalUnit').val(e.item.legalUnit);
			$('#addItem1 #moqNum').val(e.item.moqNum);
			$('#addItem1 #locID').val(e.item.locID);
			
			$('#addItem1 #remark1').val(e.item.remark1);
			$('#addItem1 #remark2').val(e.item.remark2);
			$('#addItem1 #remark3').val(e.item.remark3);
			$('#addItem1 #remark4').val(e.item.remark4);
			$('#addItem1 #remark5').val(e.item.remark5);
			$('#addItem1 #remark6').val(e.item.remark6);
	    	
			console.log("ddata-=>",ddata)
    }
//formData-=> sku=fae&ASNNum=ASN0000000000007&skuCN=few&id=7&skuEN=fae&legalUnit=423&moqNum=43&locID=afdss&remark1=134&remark2=41&remark3=34324&remark4=aafd&remark5=dfa&remark6=fad	
	function initialData(){
		console.log("asn list initialData")
		setTimeout(function () { 
			console.log("initialData 查询入库信息 changeActive");
			changeMenuActive(5);
        },1000);
	}
</script>
</html>